<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <script src="/layui/layui.js"></script>
  <script src="/js/jquery/jquery-3.5.1.js"></script>
  <script src="/js/book/book.js"></script>
  <script src="/js/book/app.min.js"></script>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/bookList.css">
  <link rel="stylesheet" href="/css/book.css">
  <link rel="stylesheet" href="/css/app.min.css">
  <title>规则修改</title>

</head>
<body>

<form class="layui-form" action="" style="padding-top: 50px;" lay-filter="book-rule">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">名称</label>
      <div class="layui-input-inline">
        <input type="text" name="ruleName"  placeholder="名称" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">根地址</label>
      <div class="layui-input-inline">
        <input type="text" name="rootSource"  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">搜索链接</label>
      <div class="layui-input-inline">
        <input type="text" name="rootSearch"  autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
  <div class="layui-form-item" style="display: none">
    <div class="layui-inline">
      <label class="layui-form-label">请求类型</label>
      <div class="layui-input-inline">
        <input type="text" name="rootType"   placeholder="请输入标题" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">数据列表</label>
      <div class="layui-input-inline">
        <input type="text" name="ruleBookList"  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">章节列表</label>
      <div class="layui-input-inline">
        <input type="text" name="ruleChapterList"  autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
  <div class="book_lable">规则定义
    <div class="layui-input-block submit-btn" >
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="saveRule">确定</button>
    </div>
  </div>
  <div>
    <div id="header" style="display: none">
      <div id="name-menu" >
        <div id="name" title="Document name. Click to change"></div>
        <div id="name-status" title="Changes are automatically saved online"></div>
      </div>
      <div id="menu" style="display: none">
        <ul>
          <li>
            <a id="new" title="Open a new, empty document">New</a>
          </li>
          <li>
            <a id="open" title="Open file">
              Open <span class="dropDownIcon">&#x25BC;</span>
            </a>
            <ul id="openMenu">
              <li>
                <a id="openFromDisk" title="Open file from disk">Open from disk</a>
              </li>
              <li>
                <a id="openUrl" title="Open file from url">Open url</a>
              </li>
              <li id="filesList"></li>
            </ul>
          </li>
          <li>
            <a id="save" title="Save file">
              Save <span class="dropDownIcon">&#x25BC;</span>
            </a>
            <ul id="saveMenu">
              <li>
                <a id="saveOnline" title="Save and share online">Save online</a>
              </li>
              <li>
                <a id="saveToDisk" title="Save file to disk">Save to disk</a>
              </li>
              <li>
                <a id="saveToUrl" title="Save to a custom url">Save to url</a>
              </li>
            </ul>
          </li>
          <li class="settings">
            <a id="settings" title="Settings">
              Settings <span class="dropDownIcon">&#x25BC;</span>
            </a>
            <ul id="settingsMenu">
              <li>
                <div class="indentation">
                  <label for="indentation">Indentation <input id="indentation" value="2"/></label>
                </div>
              </li>
              <li id="schemasList"></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>

    <div id="auto">
      <div id="contents">
        <div id="codeEditor" ></div>

        <div id="splitter" style="display: none">
          <div id="buttons">
            <div>
              <button id="toTree" class="convert" title="Copy code to tree editor (Ctrl + >)">
                <div class="convert-right"></div>
              </button>
            </div>
            <div>
              <button id="toCode" class="convert" title="Copy tree to code editor (Ctrl + <)">
                <div class="convert-left"></div>
              </button>
            </div>
          </div>
          <div id="drag">
          </div>
        </div>

        <div id="treeEditor"  style="display: none"></div>

        <div id="previewEditor"></div>

        <script type="text/javascript">
          app.load();
          app.resize();
        </script>

      </div>

      <script type="text/javascript">
        app.resize();
      </script>
    </div>

  </div>

<!--  <textarea id="demo" name="ruleSet" style="display: none" lay-verify="content" class="layui-input" ></textarea>
  <div class="layui-form-item" style="text-align: center;" >
    <div class="layui-input-block" >
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="saveRule">确定</button>
    </div>
  </div>-->

<!--  <script>
    let layedit="";
    let index="";
    layui.use(['form','layedit'], function(){
       layedit = layui.layedit;
      let form = layui.form;
       index = layedit.build('demo'); //建立编辑器
       layedit.setContent(index,"你好22222");

      form.verify({
        content: function(value) {
          return layedit.sync(index);
        }
      });

    });
  </script>-->

<script>

  var bookRule = parent.ds;
  debugger
  layui.use(['layer','form','table','layedit'], function(){
    let table = layui.table;
    let form = layui.form;
    let $ = layui.jquery;
    let layer = layui.layer;
    form.val("book-rule",bookRule)

    //监听提交
    form.on('submit(saveRule)', function(data){
      debugger
     // layedit.sync(index);
      app.sync();
      var e = app.getData().replace(/[\r\n]/g,"");
      data.field.ruleSet = e;

      var rs = JSON.stringify(data.field);

      let brset=extend(bookRule ,data.field);

      $.ajax({
        type:"put",
        url: "/BookAdmin/saveOrUpdateBookRuleSet",
        data:JSON.stringify(brset),
        dataType:"json",
        contentType : "application/json; charset=utf-8",
        success: function(res){
        }
      });
      return false;
    });
  });


  function extend(target, source) {
    if(target==undefined){
      return source;
    }
    for (var obj in source) {
      target[obj] = source[obj];
    }
    return target;
  }

</script>

</form>
<script>
  　window.onload = function(){
     $("#codeEditor").css({"width":"98%","height":"500px"});
     if(bookRule!=undefined){
       debugger
       codeEditor.set(eval('(' + bookRule.ruleSet + ')'));
     }

     //treeEditor.set(bookRule.ruleSet.replace(/[\r\n]/g,""));
     //codeEditor.set(JSON.parse(bookRule.ruleSet.replace(/[\r\n]/g,""))), treeEditor.set(bookRule.ruleSet.replace(/[\r\n]/g,""));
　　}
</script>
</body>
</html>
